#include<cstdio>
#include<iostream>
using namespace std;
const int mx = 1e4 + 10;
int a[mx];
int main() {
	int L, m, k = 0;
	cin >> L >> m;
	while (m--) {
		int x, y;
		cin >> x >> y;
		for (int i = x; i <= y; i++) a[i] = 1;
	}
	for (int i = 0; i <= L; i++) {
		if (a[i] == 0) k++;
	}
	cout << k;
	return 0;
}